import { tableColumns } from '@/config/table';
import storage from '@/utils/helper/storage';
import store from '@/store';
import { ref, unref, computed } from 'vue';
export const useTableColumns = (no: string) => {
    let columnNo = no; // 表格编号
    const newColumns = computed(() => {
        const customColumns = storage.get(`${store.getters.userInfo.employeeDTO.empId}-columns`) || {};
        if (customColumns && customColumns[columnNo]) {
            return customColumns[columnNo];
        } else {
            return tableColumns[columnNo];
        }
    });
    // 设置列
    const settingColumns = ref<any>([]);
    settingColumns.value = unref(newColumns);
    // 表格列
    const columns = computed(() => {
        return unref(settingColumns).filter((item) => (Reflect.has(item, 'checked') ? item.checked : true));
    });
    const setColumns = (newColumns: any, no: string = columnNo) => {
        columnNo = no; // 表格编号
        const customColumns = storage.get(`${store.getters.userInfo.employeeDTO.empId}-columns`) || {};
        customColumns[columnNo] = [...newColumns];
        storage.set(`${store.getters.userInfo.employeeDTO.empId}-columns`, customColumns);
        settingColumns.value = [
            ...newColumns
        ];
    };
    return {
        settingColumns,
        columns,
        setColumns
    };
};